package com.wxzz.elearing.pay.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.pay.dto.UserTransactionDto;
import com.wxzz.elearing.pay.entity.UserTransaction;
import com.wxzz.elearing.pay.service.IUserTransactionService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 余额明细 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-23
 */
@RestController
@RequestMapping("/wx-user-transaction")
@Api(tags = "余额变动(小程序)")
public class WxUserTransactionController {

    @Autowired
    private IUserTransactionService userTransactionService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "查询余额变动(小程序)", notes = "查询余额变动(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listUserTransaction", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<UserTransaction>>> listUserTransaction(@RequestHeader String token, @RequestBody UserTransactionDto userTransactionDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        userTransactionDto.setUserType(2);
        return userTransactionService.listUserTransaction(jsonObject,userTransactionDto);
    }


}
